<?php
/**
 * 广告位置管理模块
 * 
 + ----------------------------------------------------- 
 * Date 2013-3-8
 + -----------------------------------------------------
 */
class AdPositionAction extends CommonAction {
	
	public function index(){
		$map=$this->_search();
		$model=M('AdPosition');
		$this->_list($model,$map);
		$this->display();
	}
	/**
	 +----------------------------------------------------------
	 * 根据表单生成查询条件
	 * 进行列表过滤
	 +----------------------------------------------------------
	 * @access protected
	 +----------------------------------------------------------
	 * @param Model $model 数据对象
	 * @param HashMap $map 过滤条件
	 * @param string $sortBy 排序
	 * @param boolean $asc 是否正序
	 +----------------------------------------------------------
	 * @return void
	 +----------------------------------------------------------
	 * @throws ThinkExecption
	 +----------------------------------------------------------
	 */
	protected function _list($model, $map = array()) {
		$count = $model->where($map)->count('id');
		import("ORG.Util.Page");
		if (!empty($_REQUEST['listRows'])) {
			$listRows = $_REQUEST['listRows'];
		} else {
			$listRows = '15';
		}
		$p = new Page($count, $listRows);
		//分页查询数据
		$list = $model->field("id,name,add_time,CONCAT_WS('*',width,height) as size")
				->where($map)
				->order('add_time asc')
				->limit($p->firstRow . ',' . $p->listRows)
				->select();
		$new_list=array();
		if(is_array($list)&&count($list)>0){
			foreach($list as $k=>$v){
				$new_list[$k] = $v;
				$model_ad=M('Ad');
				$count_ad=$model_ad->where('position_id='.$v['id'])->count();
				$new_list[$k]['count_ad'] = $count_ad;
			}
		}
		//dump($model->getLastSql());exit;
		//分页显示
		$page = $p->show();
		//列表排序方式
		$sort = $sort == 'desc' ? 1 : 0;
		//模板赋值显示
		$this->assign('listRows',$listRows);
		$this->assign('pagesize',$this->_getPageSize());
		$this->assign('list', $new_list);
		$this->assign('sort', $sort);
		$this->assign('order', $order);
		$this->assign("page", $page);
		$this->assign("map", $map);
		Cookie::set('_currentUrl_', __SELF__);
		return;
	}
}

?>